package com.appmagna.sleepaidfan;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import com.aigestudio.wheelpicker.WheelPicker;
import com.crashlytics.android.Crashlytics;
import com.facebook.appevents.AppEventsConstants;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.internal.ServerProtocol;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import io.fabric.sdk.android.Fabric;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

@SuppressWarnings("all")
public class MainActivity extends Activity implements View.OnClickListener, WheelPicker.OnItemSelectedListener, AudioManager.OnAudioFocusChangeListener {
    public static Boolean isLoading;
    ObjectAnimator animator;
    SleepAidFanApplication app;
    ImageButton btnImageSetTimer;
    ImageButton btnMore;
    ImageButton btnOption1;
    ImageButton btnOption2;
    ImageButton btnOption3;
    Button btnSetTimer;
    Boolean didClickVolume;
    int fanSpeed;
    int focus = 0;
    ImageView imgCage;
    ImageView imgFan;
    ImageView imgMute;
    ImageView imgSliderBackground;
    Boolean isAlreadyLoaded;
    Boolean isOff;
    RelativeLayout layoutFan;
    RelativeLayout layoutHigh;
    RelativeLayout layoutLow;
    RelativeLayout layoutMid;
    RelativeLayout layoutOff;
    TextView lblMute;
    TextView lblTimer;
    int loadCount;
    AppEventsLogger logger;
    AdView mAdView;
    public Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            if (MainActivity.this.timerSecond != 0) {
                MainActivity.this.timerSecond--;
            } else if (MainActivity.this.timerMinute != 0) {
                MainActivity.this.timerMinute--;
                MainActivity.this.timerSecond = 59;
            } else if (MainActivity.this.timerHour == 0) {
                MainActivity.this.timerHour = 0;
                MainActivity.this.timerMinute = 0;
                MainActivity.this.timerSecond = 0;
                MainActivity.this.isOff = true;
                MainActivity.this.selectedVolume = 0;
                MainActivity.this.switchOption(MainActivity.this.selectedOption);
                MainActivity.this.didClickVolume = true;
                MainActivity.this.seekBarSpeed.setProgress(MainActivity.this.selectedVolume);
            } else {
                MainActivity.this.timerHour--;
                MainActivity.this.timerMinute = 59;
                MainActivity.this.timerSecond = 59;
            }
            MainActivity.this.setTimerLabel();
            if (MainActivity.this.timerHour == 0 && MainActivity.this.timerMinute == 0 && MainActivity.this.timerSecond == 0) {
                if (MainActivity.this.timer != null) {
                    MainActivity.this.timer.cancel();
                }
                MainActivity.this.isOff = true;
                MainActivity.this.timer = null;
                MainActivity.this.timerHour = 0;
                MainActivity.this.timerMinute = 0;
                MainActivity.this.timerSecond = 0;
                MainActivity.this.setTimerLabel();
                MainActivity.this.timer_run = false;
                MainActivity.this.selectedVolume = 0;
                MainActivity.this.switchOption(MainActivity.this.selectedOption);
                MainActivity.this.didClickVolume = true;
                MainActivity.this.seekBarSpeed.setProgress(MainActivity.this.selectedVolume);
            }
        }
    };
    InterstitialAd mInterstitialAd;
    LoopMediaPlayer mLoopPlayer;
    MediaPlayer mPlayer;
    int noiseId;
    Uri noiseUri;
    Boolean removeAdPurchased;
    long s1;
    SeekBar seekBarSpeed;
    int selectedOption;
    int selectedVolume;
    boolean stop = false;
    public int tempHour;
    public int tempMinute;
    Timer timer;
    Dialog timerDialog;
    int timerHour;
    int timerMinute;
    int timerSecond;
    boolean timer_run = false;
    WheelPicker wheelHour;
    WheelPicker wheelMinute;

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fabric.with(this, new Crashlytics());
        setContentView(R.layout.activity_main);
        this.app = SleepAidFanApplication.getInstance();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        this.app.setDisplayMode(displayMetrics.widthPixels, displayMetrics.heightPixels, displayMetrics.density);
        this.logger = AppEventsLogger.newLogger(getApplicationContext());
        this.logger.logEvent("App Launch");
        if (!getSharedPreferences("appRater", 0).getString("shownPrompt", "").equals(ServerProtocol.DIALOG_RETURN_SCOPES_TRUE)) {
            AppRater.launchCount(this);
        }
        int requestAudioFocus = ((AudioManager) getSystemService("audio")).requestAudioFocus(this, 3, 1);
        isLoading = false;
        this.isAlreadyLoaded = false;
        this.fanSpeed = 0;
        this.selectedOption = 2;
        this.isOff = true;
        this.selectedVolume = 0;
        this.timer = null;
        this.mPlayer = null;
        this.mLoopPlayer = null;
        this.didClickVolume = false;
        loadPreference();
        this.imgFan = (ImageView) findViewById(R.id.imgFan);
        this.imgCage = (ImageView) findViewById(R.id.imgCage);
        this.imgSliderBackground = (ImageView) findViewById(R.id.imgSliderBackground);
        this.lblTimer = (TextView) findViewById(R.id.lblTimer);
        this.animator = ObjectAnimator.ofFloat(this.imgFan, "rotation", new float[]{0.0f, 360.0f});
        this.animator.setInterpolator(new LinearInterpolator());
        this.animator.setRepeatCount(-1);
        this.animator.setDuration((long) this.fanSpeed);
        this.animator.start();
        this.seekBarSpeed = (SeekBar) findViewById(R.id.seekBarSpeed);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) this.seekBarSpeed.getLayoutParams();
        params.setMargins(displayMetrics.widthPixels / 8, 0, displayMetrics.widthPixels / 8, 0);
        this.seekBarSpeed.setLayoutParams(params);
        this.seekBarSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onStopTrackingTouch(SeekBar seekBar) {
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (MainActivity.this.didClickVolume.booleanValue() || MainActivity.this.selectedVolume != progress) {
                    MainActivity.this.didClickVolume = false;
                    MainActivity.this.selectedVolume = progress;
                    MainActivity.this.switchOption(MainActivity.this.selectedOption);
                    if (progress == 0) {
                        if (Locale.getDefault().getLanguage().toString().equals("en")) {
                            MainActivity.this.logger.logEvent("Off Button (English Version)");
                        } else {
                            MainActivity.this.logger.logEvent("Off Button (Non-English Version)");
                        }
                        SharedPreferences prefs = MainActivity.this.getSharedPreferences("appRater", 0);
                        long launch_count = prefs.getLong("launch_count", 0);
                        if (prefs.contains("remind_date")) {
                            if (System.currentTimeMillis() >= Long.valueOf(prefs.getLong("remind_date", 0)).longValue() + ((long) 864000000)) {
                                MainActivity.this.logger.logEvent("Reminder Me Later Review Prompt Shown");
                                MainActivity.this.showRatingDialog();
                            }
                        } else if (launch_count >= 8) {
                            SharedPreferences.Editor editor = prefs.edit();
                            editor.putString("shownPrompt", ServerProtocol.DIALOG_RETURN_SCOPES_TRUE);
                            editor.commit();
                            MainActivity.this.showFeedbackDialog();
                        }
                        MainActivity.this.fanSpeed = 0;
                        MainActivity.this.isOff = true;
                        MainActivity.this.timerHour = 0;
                        MainActivity.this.timerMinute = 0;
                        MainActivity.this.timerSecond = 0;
                        MainActivity.this.setTimerLabel();
                        if (MainActivity.this.timer != null) {
                            MainActivity.this.timer.cancel();
                        }
                        MainActivity.this.timer = null;
                        MainActivity.this.timer_run = false;
                    } else {
                        if (progress == 1) {
                            MainActivity.this.logger.logEvent("Set Volume Low");
                        } else if (progress == 2) {
                            MainActivity.this.logger.logEvent("Set Volume Medium");
                        } else if (progress == 3) {
                            MainActivity.this.logger.logEvent("Set Volume High");
                        }
                        if (MainActivity.this.timer != null && MainActivity.this.isOff.booleanValue()) {
                            MainActivity.this.timer.scheduleAtFixedRate(new MyTimer(), 0, 1000);
                        }
                        MainActivity.this.fanSpeed = 800 - (progress * 200);
                        Log.e("speed", String.valueOf(MainActivity.this.fanSpeed));
                        MainActivity.this.isOff = false;
                    }
                    MainActivity.this.animator.setDuration((long) MainActivity.this.fanSpeed);
                    MainActivity.this.animator.start();
                    if (MainActivity.this.isOff.booleanValue()) {
                        MainActivity.this.playNoise();
                    } else if (MainActivity.this.mLoopPlayer == null) {
                        MainActivity.this.playNoise();
                    } else if (MainActivity.this.mLoopPlayer.getSoundPool() == null || MainActivity.this.mLoopPlayer.getStreamId() == 0) {
                        MainActivity.this.playNoise();
                    } else {
                        Log.e("volume", String.valueOf(((float) MainActivity.this.selectedVolume) / 3.0f));
                        MainActivity.this.mLoopPlayer.getSoundPool().setVolume(MainActivity.this.mLoopPlayer.getStreamId(), ((float) MainActivity.this.selectedVolume) / 3.0f, ((float) MainActivity.this.selectedVolume) / 3.0f);
                    }
                }
            }
        });
        this.btnOption1 = (ImageButton) findViewById(R.id.btnFanOption1);
        this.btnOption1.setOnClickListener(this);
        this.btnOption2 = (ImageButton) findViewById(R.id.btnFanOption2);
        this.btnOption2.setOnClickListener(this);
        this.btnOption3 = (ImageButton) findViewById(R.id.btnFanOption3);
        this.btnOption3.setOnClickListener(this);
        this.btnSetTimer = (Button) findViewById(R.id.btnSetTimer);
        this.btnSetTimer.setOnClickListener(this);
        this.btnImageSetTimer = (ImageButton) findViewById(R.id.btnImageSetTimer);
        this.btnImageSetTimer.setOnClickListener(this);
        this.btnMore = (ImageButton) findViewById(R.id.btnMore);
        this.btnMore.setOnClickListener(this);
        this.lblMute = (TextView) findViewById(R.id.lblMute);
        this.imgMute = (ImageView) findViewById(R.id.imgMute);
        this.layoutOff = (RelativeLayout) findViewById(R.id.layoutOff);
        this.layoutOff.setOnClickListener(this);
        this.layoutLow = (RelativeLayout) findViewById(R.id.layoutLow);
        this.layoutLow.setOnClickListener(this);
        this.layoutMid = (RelativeLayout) findViewById(R.id.layoutMid);
        this.layoutMid.setOnClickListener(this);
        this.layoutHigh = (RelativeLayout) findViewById(R.id.layoutHigh);
        this.layoutHigh.setOnClickListener(this);
        this.layoutFan = (RelativeLayout) findViewById(R.id.layoutFan);
        this.layoutFan.setOnClickListener(this);
        switchOption(this.selectedOption);
        setUpLocalizationSetting();
        playNoise();
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnMore:
                this.logger.logEvent("More Button");
                startActivity(new Intent(this, MoreActivity.class));
                overridePendingTransition(R.anim.slide_in_up, R.anim.stay);
                return;
            case R.id.layoutFan:
                if (this.selectedVolume == 0) {
                    this.selectedVolume = 1;
                    this.logger.logEvent("Fan On (Pressing the big fan to turn it on)");
                } else {
                    this.selectedVolume = 0;
                    if (Locale.getDefault().getLanguage().toString().equals("en")) {
                        this.logger.logEvent("Fan Off (Pressing the big fan to turn it off - English Version)");
                    } else {
                        this.logger.logEvent("Fan Off (Pressing the big fan to turn it off - Non-English Version)");
                    }
                }
                switchOption(this.selectedOption);
                this.didClickVolume = true;
                this.seekBarSpeed.setProgress(this.selectedVolume);
                return;
            case R.id.layoutOff:
                this.selectedVolume = 0;
                this.didClickVolume = true;
                this.seekBarSpeed.setProgress(this.selectedVolume);
                switchOption(this.selectedOption);
                return;
            case R.id.layoutLow:
                this.selectedVolume = 1;
                this.didClickVolume = true;
                this.seekBarSpeed.setProgress(this.selectedVolume);
                switchOption(this.selectedOption);
                return;
            case R.id.layoutMid:
                this.selectedVolume = 2;
                this.didClickVolume = true;
                this.seekBarSpeed.setProgress(this.selectedVolume);
                switchOption(this.selectedOption);
                return;
            case R.id.layoutHigh:
                this.selectedVolume = 3;
                this.didClickVolume = true;
                this.seekBarSpeed.setProgress(this.selectedVolume);
                switchOption(this.selectedOption);
                return;
            case R.id.btnSetTimer:
            case R.id.btnImageSetTimer:
                this.logger.logEvent("Set Timer");
                showTimerDialog();
                return;
            case R.id.btnFanOption1:
                if (this.selectedOption != 1) {
                    this.selectedOption = 1;
                    switchOption(this.selectedOption);
                    playNoise();
                    return;
                }
                return;
            case R.id.btnFanOption2:
                if (this.selectedOption != 2) {
                    this.selectedOption = 2;
                    switchOption(this.selectedOption);
                    playNoise();
                    return;
                }
                return;
            case R.id.btnFanOption3:
                if (this.selectedOption != 3) {
                    this.selectedOption = 3;
                    switchOption(this.selectedOption);
                    playNoise();
                    return;
                }
                return;
            default:
                return;
        }
    }

    public void switchOption(int selectedOption2) {
        if (!isLoading.booleanValue()) {
            int dpAsPixels = (int) ((8.0f * getResources().getDisplayMetrics().density) + 0.5f);
            this.btnOption1.setImageDrawable(getResources().getDrawable(R.drawable.bottom3_unselected));
            this.btnOption2.setImageDrawable(getResources().getDrawable(R.drawable.bottom4_unselected));
            this.btnOption3.setImageDrawable(getResources().getDrawable(R.drawable.bottom5_unselected));
            this.btnOption1.setPadding(dpAsPixels, dpAsPixels, dpAsPixels, dpAsPixels);
            this.btnOption2.setPadding(dpAsPixels, dpAsPixels, dpAsPixels, dpAsPixels);
            this.btnOption3.setPadding(dpAsPixels, dpAsPixels, dpAsPixels, dpAsPixels);
            if (selectedOption2 == 1) {
                this.btnOption1.setImageDrawable(getResources().getDrawable(R.drawable.bottom3_selected));
                this.btnOption1.setPadding(0, 0, 0, 0);
                if (this.selectedVolume == 0) {
                    this.imgFan.setImageDrawable(getResources().getDrawable(R.drawable.fanblade3));
                } else {
                    this.imgFan.setImageDrawable(getResources().getDrawable(R.drawable.fanblade3_noshadow));
                }
                this.imgCage.setImageDrawable(getResources().getDrawable(R.drawable.cage3));
                this.imgSliderBackground.setImageDrawable(getResources().getDrawable(R.drawable.volumebar3));
                this.btnSetTimer.setBackgroundResource(getResources().getIdentifier("button_timer1", "drawable", getPackageName()));
                this.btnImageSetTimer.setBackgroundResource(getResources().getIdentifier("button_timer1", "drawable", getPackageName()));
                this.logger.logEvent("Fan Noise 1");
                this.noiseUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.noise_31);
                this.noiseId = R.raw.noise_31;
            } else if (selectedOption2 == 2) {
                this.btnOption2.setImageDrawable(getResources().getDrawable(R.drawable.bottom4_selected));
                this.btnOption2.setPadding(0, 0, 0, 0);
                if (this.selectedVolume == 0) {
                    this.imgFan.setImageDrawable(getResources().getDrawable(R.drawable.fanblade4));
                } else {
                    this.imgFan.setImageDrawable(getResources().getDrawable(R.drawable.fanblade4_noshadow));
                }
                this.imgCage.setImageDrawable(getResources().getDrawable(R.drawable.cage4));
                this.imgSliderBackground.setImageDrawable(getResources().getDrawable(R.drawable.volumebar4));
                this.btnSetTimer.setBackgroundResource(getResources().getIdentifier("button_timer2", "drawable", getPackageName()));
                this.btnImageSetTimer.setBackgroundResource(getResources().getIdentifier("button_timer2", "drawable", getPackageName()));
                this.logger.logEvent("Fan Noise 2");
                this.noiseUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.noise_41);
                this.noiseId = R.raw.noise_41;
            } else if (selectedOption2 == 3) {
                this.btnOption3.setImageDrawable(getResources().getDrawable(R.drawable.bottom5_selected));
                this.btnOption3.setPadding(0, 0, 0, 0);
                if (this.selectedVolume == 0) {
                    this.imgFan.setImageDrawable(getResources().getDrawable(R.drawable.fanblade5));
                } else {
                    this.imgFan.setImageDrawable(getResources().getDrawable(R.drawable.fanblade5_noshadow));
                }
                this.imgCage.setImageDrawable(getResources().getDrawable(R.drawable.cage5));
                this.imgSliderBackground.setImageDrawable(getResources().getDrawable(R.drawable.volumebar5));
                this.btnSetTimer.setBackgroundResource(getResources().getIdentifier("button_timer3", "drawable", getPackageName()));
                this.btnImageSetTimer.setBackgroundResource(getResources().getIdentifier("button_timer3", "drawable", getPackageName()));
                this.logger.logEvent("Fan Noise 3");
                this.noiseUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.noise_51);
                this.noiseId = R.raw.noise_51;
            }
        }
    }

    public void setTimerLabel() {
        String strTime;
        String strTime2;
        String strTime3;
        if (this.timerHour < 10) {
            strTime = AppEventsConstants.EVENT_PARAM_VALUE_NO + String.valueOf(this.timerHour);
        } else {
            strTime = String.valueOf(this.timerHour);
        }
        if (this.timerMinute < 10) {
            strTime2 = strTime + ":0" + String.valueOf(this.timerMinute);
        } else {
            strTime2 = strTime + ":" + String.valueOf(this.timerMinute);
        }
        if (this.timerSecond < 10) {
            strTime3 = strTime2 + ":0" + String.valueOf(this.timerSecond);
        } else {
            strTime3 = strTime2 + ":" + String.valueOf(this.timerSecond);
        }
        this.lblTimer.setText(strTime3);
    }

    public void loadPreference() {
        int i = getResources().getDisplayMetrics().densityDpi;
        int dimension = (int) getResources().getDimension(R.dimen.selectionFanSize);
        float f = getResources().getDisplayMetrics().density;
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        this.loadCount = prefs.getInt("NumberOfLoading", 0);
        this.removeAdPurchased = Boolean.valueOf(prefs.getBoolean("removeAdPurchased", false));
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
        this.loadCount++;
        editor.putInt("NumberOfLoading", this.loadCount);
        editor.commit();
        if (!this.removeAdPurchased.booleanValue()) {
            this.mAdView = (AdView) findViewById(R.id.adView);
            this.mAdView.loadAd(new AdRequest.Builder().build());
            if (this.loadCount != 1 && this.loadCount != 8 && !this.isAlreadyLoaded.booleanValue()) {
                this.mInterstitialAd = new InterstitialAd(this);
                this.mInterstitialAd.setAdUnitId(getString(R.string.admob_interstitial_full_screen));
                this.mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB").build());
                this.mInterstitialAd.setAdListener(new AdListener() {
                    public void onAdLoaded() {
                        MainActivity.this.showInterstitial();
                    }
                });
            }
        }
    }

    /* access modifiers changed from: private */
    public void showInterstitial() {
        if (this.loadCount != 1 && this.loadCount != 8 && !this.isAlreadyLoaded.booleanValue() && !this.removeAdPurchased.booleanValue() && this.mInterstitialAd.isLoaded()) {
            this.isAlreadyLoaded = true;
            this.mInterstitialAd.show();
        }
    }

    public void playNoise() {
        Log.e("URI", this.noiseUri.toString());
        if (isLoading.booleanValue()) {
            Log.e("=====CANCEL======", "=======CANCEL=====");
            return;
        }
        Log.e("=========PASS==========", "=======PASS========");
        isLoading = true;
        if (!this.isOff.booleanValue()) {
            if (this.mLoopPlayer != null) {
                this.mLoopPlayer.stopPlay();
                this.mLoopPlayer = null;
            }
            this.mLoopPlayer = null;
            this.mLoopPlayer = new LoopMediaPlayer(this, this.noiseId, ((float) this.selectedVolume) / 3.0f);
            this.stop = false;
        } else {
            if (this.mLoopPlayer != null) {
                this.mLoopPlayer.stopPlay();
                this.mLoopPlayer = null;
            }
            this.mLoopPlayer = null;
        }
        Log.e("========Loaded=======", "==========Loaded=========");
        isLoading = false;
    }

    private void showTimerDialog() {
        this.tempHour = 0;
        this.tempMinute = 0;
        this.timerDialog = new Dialog(this, 16973840);
        this.timerDialog.setContentView(R.layout.dialog_timer);
        this.timerDialog.setCancelable(false);
        Window window = this.timerDialog.getWindow();
        WindowManager.LayoutParams wlp = window.getAttributes();
        wlp.gravity = 80;
        wlp.flags &= -3;
        wlp.width = -1;
        wlp.height = -1;
        window.setAttributes(wlp);
        this.wheelHour = (WheelPicker) this.timerDialog.findViewById(R.id.hourWheel);
        this.wheelHour.setOnItemSelectedListener(this);
        this.wheelMinute = (WheelPicker) this.timerDialog.findViewById(R.id.minWheel);
        this.wheelMinute.setOnItemSelectedListener(this);
        Button btnDone = (Button) this.timerDialog.findViewById(R.id.btnDone);
        btnDone.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MainActivity.this.timerDoneClick();
            }
        });
        ImageButton btnImageDone = (ImageButton) this.timerDialog.findViewById(R.id.btnImageDone);
        btnImageDone.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MainActivity.this.timerDoneClick();
            }
        });
        Button btnCancel = (Button) this.timerDialog.findViewById(R.id.btnCancel);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MainActivity.this.logger.logEvent("Timer Pop Up Cancel");
                MainActivity.this.timerDialog.dismiss();
            }
        });
        ImageButton btnImageCancel = (ImageButton) this.timerDialog.findViewById(R.id.btnImageCancel);
        btnImageCancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MainActivity.this.logger.logEvent("Timer Pop Up Cancel");
                MainActivity.this.timerDialog.dismiss();
            }
        });
        TextView lblHr = (TextView) this.timerDialog.findViewById(R.id.lblHr);
        TextView lblMin = (TextView) this.timerDialog.findViewById(R.id.lblMin);
        TextView lblSemiColon = (TextView) this.timerDialog.findViewById(R.id.lblSemiColon);
        if (Locale.getDefault().getLanguage().toString().equals("en")) {
            lblHr.setVisibility(0);
            lblMin.setVisibility(0);
            btnDone.setVisibility(0);
            btnCancel.setVisibility(0);
            btnImageDone.setVisibility(8);
            btnImageCancel.setVisibility(8);
            lblSemiColon.setVisibility(8);
        } else {
            lblHr.setVisibility(4);
            lblMin.setVisibility(4);
            lblSemiColon.setVisibility(0);
            btnDone.setVisibility(8);
            btnCancel.setVisibility(8);
            btnImageDone.setVisibility(0);
            btnImageCancel.setVisibility(0);
        }
        this.timerDialog.show();
    }

    public void onItemSelected(WheelPicker wheelPicker, Object o, int i) {
        switch (wheelPicker.getId()) {
            case R.id.hourWheel:
                this.tempHour = i;
                return;
            case R.id.minWheel:
                this.tempMinute = i;
                return;
            default:
                return;
        }
    }

    public void setUpLocalizationSetting() {
        if (Locale.getDefault().getLanguage().toString().equals("en")) {
            this.btnMore.setVisibility(0);
            this.btnSetTimer.setVisibility(0);
            this.btnImageSetTimer.setVisibility(4);
            this.lblMute.setVisibility(0);
            this.imgMute.setVisibility(4);
            return;
        }
        this.btnMore.setVisibility(4);
        this.btnSetTimer.setVisibility(4);
        this.btnImageSetTimer.setVisibility(0);
        this.lblMute.setVisibility(4);
        this.imgMute.setVisibility(0);
    }

    public void timerDoneClick() {
        this.logger.logEvent("Timer Pop Up Done");
        this.timerHour = this.tempHour;
        this.timerMinute = this.tempMinute;
        this.timerSecond = 0;
        setTimerLabel();
        if (this.selectedVolume == 0 || this.selectedOption == 0) {
            this.isOff = true;
        } else {
            this.isOff = false;
        }
        if (this.timer != null) {
            this.timer.cancel();
            this.timer = null;
        }
        this.timer = new Timer();
        if (!this.isOff.booleanValue() && !(this.timerHour == 0 && this.timerMinute == 0)) {
            this.timer.scheduleAtFixedRate(new MyTimer(), 0, 1000);
            this.timer_run = true;
        }
        this.timerDialog.dismiss();
    }

    public void onBackPressed() {
        moveTaskToBack(true);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode != 4) {
            return super.onKeyDown(keyCode, event);
        }
        moveTaskToBack(true);
        return true;
    }

    public void onAudioFocusChange(int focusChange) {
        if (focusChange == -2) {
            this.focus = -2;
            Log.e("@pause", "pause");
            if (this.mLoopPlayer != null) {
                this.mLoopPlayer.stopPlay();
                this.mLoopPlayer = null;
            }
            this.stop = true;
            if (this.timer != null) {
                this.timer.cancel();
                this.timer = null;
            }
            this.animator.setDuration(0);
            this.animator.start();
        } else if (focusChange == 1) {
            this.focus = 1;
            resumeTimer();
            Log.e("focusGain", "focusGain");
            this.animator.setDuration((long) this.fanSpeed);
            this.animator.start();
            playNoise();
        } else if (focusChange == -1) {
            this.focus = -1;
            Log.e("@stop", "stop");
            if (this.mLoopPlayer != null) {
                this.mLoopPlayer.stopPlay();
                this.mLoopPlayer = null;
            }
            this.stop = true;
            if (this.timer != null) {
                this.timer.cancel();
                this.timer = null;
            }
            this.animator.setDuration(0);
            this.animator.start();
        }
    }

    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            int result = ((AudioManager) getSystemService("audio")).requestAudioFocus(this, 3, 1);
            Log.e("focus", String.valueOf(this.focus));
            if (result == 1 && (this.focus == -1 || this.focus == -2)) {
                resumeTimer();
                Log.e("windowFocus", "windowFocus");
                Log.e("stop", String.valueOf(this.stop));
                if (this.stop) {
                    this.animator.setDuration((long) this.fanSpeed);
                    this.animator.start();
                    playNoise();
                }
            } else if (result == 0) {
                this.selectedVolume = 0;
                this.didClickVolume = true;
                this.seekBarSpeed.setProgress(this.selectedVolume);
                switchOption(this.selectedOption);
                Log.e("fails", "fails");
            }
        }
    }

    public void resumeTimer() {
        Log.e("timerRun", String.valueOf(this.timer_run));
        if (this.timer == null && this.timer_run) {
            this.timer = new Timer();
            if (this.s1 != 0) {
                this.timer.scheduleAtFixedRate(new MyTimer(), 0, 1000);
                this.timer_run = true;
            }
        }
    }

    public void showFeedbackDialog() {
        this.logger.logEvent("Love prompt shown");
        AppRater.resetLaunchCount(this);
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage((CharSequence) getResources().getString(R.string.feedback_msg));
        alertDialogBuilder.setPositiveButton((CharSequence) "Yes", (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                MainActivity.this.logger.logEvent("Yes pressed on Love Prompt");
                MainActivity.this.showRatingDialog();
            }
        });
        alertDialogBuilder.setNegativeButton((CharSequence) "No", (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                MainActivity.this.logger.logEvent("No Pressed on Love Prompt");
                MainActivity.this.showEmailIntent();
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.setCancelable(false);
        alertDialog.show();
    }

    public void showRatingDialog() {
        AppRater.resetLaunchCount(this);
        AppRater.removeRemindLater(this);
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle((CharSequence) getResources().getString(R.string.rating_title));
        alertDialogBuilder.setMessage((CharSequence) getResources().getString(R.string.rating_msg));
        alertDialogBuilder.setPositiveButton((CharSequence) "Rate Sleep Aid Fan", (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                MainActivity.this.logger.logEvent("Rate Sleep Aid Fan clicked");
                Intent goToMarket = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + MainActivity.this.getPackageName()));
                goToMarket.addFlags(1208483840);
                try {
                    MainActivity.this.startActivity(goToMarket);
                } catch (ActivityNotFoundException e) {
                    MainActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=" + MainActivity.this.getPackageName())));
                }
            }
        });
        alertDialogBuilder.setNeutralButton((CharSequence) "No thanks", (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                MainActivity.this.logger.logEvent("No Thanks Clicked");
                dialog.dismiss();
            }
        });
        alertDialogBuilder.setNegativeButton((CharSequence) "Remind Me Later", (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                MainActivity.this.logger.logEvent("Remind Me Later clicked");
                AppRater.remindLater(MainActivity.this);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.setCancelable(false);
        alertDialog.show();
    }

    public void showEmailIntent() {
        Intent emailIntent = new Intent("android.intent.action.SENDTO", Uri.fromParts("mailto", "support@appmagna.com ", (String) null));
        emailIntent.putExtra("android.intent.extra.SUBJECT", getResources().getString(R.string.email_subject));
        emailIntent.putExtra("android.intent.extra.TEXT", getResources().getString(R.string.email_body));
        startActivity(Intent.createChooser(emailIntent, "Send email..."));
    }

    class MyTimer extends TimerTask {
        MyTimer() {
        }

        public void run() {
            MainActivity.this.mHandler.obtainMessage(1).sendToTarget();
        }
    }
}
